﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Mvc;

namespace Sketch.Controllers
{
    public partial class ContentController : ApplicationController
    {
        private readonly AppSettings _appSettings;

        public ContentController()
        {
            _appSettings = new AppSettings();
        }

        [ActionName("icons")]
        public virtual ActionResult GetIcons(string type)
        {
            var model = GetFilesInFolder(_appSettings.IconsPath, type);
            return PartialView(Views.images, model);
        }

        private List<string> GetFilesInFolder(string folder, string subFolder)
        {
            var fullPath = Path.Combine(folder, subFolder);
            var files = Directory.GetFiles(Server.MapPath(fullPath));
            return files.Select(x => Path.Combine(folder, subFolder, Path.GetFileName(x)).Replace("\\", "//")).ToList();
        }
    }
}